package com.tjec.project.businessWorkbench.controller;

import java.util.List;

import com.tjec.framework.interceptor.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tjec.framework.aspectj.lang.annotation.Log;
import com.tjec.framework.aspectj.lang.enums.BusinessType;
import com.tjec.framework.security.service.TokenService;
import com.tjec.project.businessWorkbench.domain.AttachmentVo;
import com.tjec.project.businessWorkbench.domain.BmsBusinessDocArchive;
import com.tjec.project.businessWorkbench.dto.BmsAttachmentDto;
import com.tjec.project.businessWorkbench.service.IBmsBusinessDocArchiveService;
import com.tjec.project.projectWorkbench.service.impl.BmsReportNoServiceImpl;
import com.tjec.project.system.service.IBmsAttachmentService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import com.tjec.framework.web.controller.BaseController;
import com.tjec.framework.web.domain.AjaxResult;
import com.tjec.common.utils.ServletUtils;
import com.tjec.common.utils.poi.ExcelUtil;
import com.tjec.framework.web.page.TableDataInfo;

/**
 * 资料归档Controller
 * 
 * @author pangyongfeng
 * @date 2020-05-18
 */
@Api(value = "资料归档", tags = {"资料归档接口"})
@RestController
@RequestMapping("/businessWorkbench/archive")
public class BmsBusinessDocArchiveController extends BaseController
{
    @Autowired
    private IBmsBusinessDocArchiveService bmsBusinessDocArchiveService;
    
    @Autowired
    private TokenService tokenService;

    @Autowired
    private IBmsAttachmentService bmsAttachmentService;
    
    @Autowired
    private BmsReportNoServiceImpl bmsReportNoServiceImpl;
    /**
     * 查询资料归档列表
     */
    @ApiOperation("查询资料归档列表")
    @PreAuthorize("@ss.hasPermi('businessWorkbench:archive:list')")
    @GetMapping("/list")
    public TableDataInfo list(BmsBusinessDocArchive bmsBusinessDocArchive)
    {
        startPage();
        List<BmsBusinessDocArchive> list = bmsBusinessDocArchiveService.selectBmsBusinessDocArchiveList(bmsBusinessDocArchive);
        return getDataTable(list);
    }
    
    /**
     * 查询资料归档附件
     */
    @ApiOperation("查询资料归档")
    @GetMapping("/listAttachments")
    public AjaxResult listAttachments(BmsBusinessDocArchive bmsBusinessDocArchive)
    {
        List<BmsAttachmentDto> list = bmsBusinessDocArchiveService.selectAttachments(bmsBusinessDocArchive);
        return AjaxResult.success(list);
    }
    
    /**
     * 查询资料归档列表
     */
    @ApiOperation("查询资料归档列表")
    @PreAuthorize("@ss.hasPermi('businessWorkbench:archive:list')")
    @GetMapping("/listInDoc")
    public TableDataInfo listInDoc(BmsBusinessDocArchive bmsBusinessDocArchive)
    {
        startPage();
        List<BmsBusinessDocArchive> list = bmsBusinessDocArchiveService.selectBmsBusinessDocArchiveListInDoc(bmsBusinessDocArchive);
        return getDataTable(list);
    }

    /**
     * 导出资料归档列表
     */
    @ApiOperation("导出资料归档列表")
    //@PreAuthorize("@ss.hasPermi('businessWorkbench:archive:export')")
    @Log(title = "资料归档", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BmsBusinessDocArchive bmsBusinessDocArchive)
    {
        List<BmsBusinessDocArchive> list = bmsBusinessDocArchiveService.selectBmsBusinessDocArchiveList(bmsBusinessDocArchive);
        ExcelUtil<BmsBusinessDocArchive> util = new ExcelUtil<BmsBusinessDocArchive>(BmsBusinessDocArchive.class);
        return util.exportExcel(list, "archive");
    }

    /**
     * 获取资料归档详细信息
     */
    @ApiOperation("获取资料归档详细信息")
    //@PreAuthorize("@ss.hasPermi('businessWorkbench:archive:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(bmsBusinessDocArchiveService.selectBmsBusinessDocArchiveByGuid(guid));
    }

    /**
     * 新增资料归档
     */
    @ApiOperation("新增资料归档")
    //@PreAuthorize("@ss.hasPermi('businessWorkbench:archive:add')")
    @Log(title = "资料归档", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping
    public AjaxResult add(@RequestBody BmsBusinessDocArchive bmsBusinessDocArchive)
    {
    	bmsBusinessDocArchive.setCreateBy(tokenService.getLoginUser(ServletUtils.getRequest()).getUser().getUserId());
        return toAjax(bmsBusinessDocArchiveService.insertBmsBusinessDocArchive(bmsBusinessDocArchive));
    }

    /**
     * 修改资料归档
     * @throws Exception 
     */
    @ApiOperation("修改资料归档")
    //@PreAuthorize("@ss.hasPermi('businessWorkbench:archive:edit')")
    @Log(title = "资料归档", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BmsBusinessDocArchive bmsBusinessDocArchive) throws Exception
    {
    	bmsBusinessDocArchive.setUpdateBy(tokenService.getLoginUser(ServletUtils.getRequest()).getUser().getUserId());
        return toAjax(bmsBusinessDocArchiveService.updateBmsBusinessDocArchive(bmsBusinessDocArchive));
    }

    /**
     * 删除资料归档
     */
    @ApiOperation("删除资料归档")
    //@PreAuthorize("@ss.hasPermi('businessWorkbench:archive:remove')")
    @Log(title = "资料归档", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids) throws Exception
    {
        return toAjax(bmsBusinessDocArchiveService.deleteBmsBusinessDocArchiveByGuids(guids));
    }
    
    /**
     * 获取附件集合
     */
    @ApiOperation("获取附件集合")
    @GetMapping(value = "getAttachments/{bizId}")
    public AjaxResult getAttachments(@PathVariable("bizId") String bizId)
    {
        return AjaxResult.success(bmsAttachmentService.selectBmsAttachmentByBizId(bizId));
    }
    
    /**
     * 获取资料归档的状态和是否可以归档的状态
     */
    @ApiOperation("获取资料归档的状态和是否可以归档的状态")
    @GetMapping(value = "getArchiveAllStatus/{businessId}")
    public AjaxResult getArchiveAllStatus(@PathVariable("businessId") String businessId)
    {
        return AjaxResult.success(bmsBusinessDocArchiveService.selectArchiveAllStatus(businessId));
    }
    
    /**
     * 获取资料归档的状态和是否可以归档的状态
     */
    @ApiOperation("获取资料归档的状态和是否可以归档的状态")
    @GetMapping(value = "getDocArchiveByBusinessId/{businessId}")
    public AjaxResult selectDocArchiveByBusinessId(@PathVariable("businessId") String businessId)
    {
        return AjaxResult.success(bmsBusinessDocArchiveService.selectDocArchiveByBusinessId(businessId));
    }
    
    @ApiOperation("根据业务id获取咨询和造价报告号")
    @GetMapping("/getReports/{businessId}")
    public AjaxResult getReportsByBusinessId(@PathVariable("businessId") String businessId) {
    	return AjaxResult.success(bmsReportNoServiceImpl.selectReportsByBusinessId(businessId));
    }
}
